export const DEFAULT_MOUSE_GESTURE = {
  enableMouseGesture: true,
  part_env: [
    'cmdFitView',
    'cmdSketchIn',
    'cmdStretch',
    'cmdResizeToArea',
    'cmdFrontView',
    'cmdBackView',
    'cmdLeftView',
    'cmdRightView',
    'cmdTopView',
    'cmdBottomView',
    'cmdIsometricView',
    'cmdUndo',
  ],
  sketch_env: [
    'cmdFitView',
    'cmdSketchOut',
    'cmdVerticalView',
    'cmdLine2',
    'cmdCircle',
    'cmdDiagonal',
    'cmdTrim',
    'cmdArc',
    'Dimintegration',
    'cmdSketchSpline',
    'cmdSketchOffset',
    'cmdConstLine',
  ],
  product_env: [
    'cmdConstrain',
    'cmdMeasure',
    'cmdFitView',
    'cmdLeftView',
    'cmdRightView',
    'cmdTopView',
    'cmdBottomView',
    'cmdFrontView',
    'cmdBackView',
    'cmdIsometricView',
    'cmdSectionView',
    'cmdUndo',
  ],
};

// 默认操作习惯配置
export const DEFAULT_USER_HABIT = {
  toolbarPosition: 'bottom',
  cadType: 'NEXT',
  customConfig: {
    pan: { key: '', mouse: 'mouse-middle-click' },
    zoom: { key: '', mouse: 'mouse-middle-move' },
    rotate: { key: '', mouse: 'mouse-right-click' },
  },
} as CmdSettingSpace.UserHabit;

// 鼠标操作映射到按钮值
export const MOUSE_OPTION_TO_BUTTON = {
  'mouse-middle-move': 4,
  'mouse-middle-click': 4,
  'mouse-right-click': 2,
  'mouse-middle-right-click': 6,
};

// 控制方案映射表
export const CAD_TYPE_TO_SCHEME = [
  'NEXT',
  'CATIA',
  'SolidWorks',
  'UG/NX',
  'Creo',
  'Inventor',
  'Custom',
];

/**
 * 根据自定义操作配置生成自定义控制方案配置
 * @param customConfig 自定义操作配置
 * @returns 适用于sceneSetup.setCustomControlScheme的控制方案配置
 */
export function generateCustomControlSchemeConfig(
  customConfig: CmdSettingSpace.CadOperationConfig,
) {
  if (!customConfig) return null;

  const { rotate, pan, zoom } = customConfig;

  // 获取按钮配置
  const rotateMouse =
    MOUSE_OPTION_TO_BUTTON[
      rotate?.mouse as keyof typeof MOUSE_OPTION_TO_BUTTON
    ] ?? 0;
  const panMouse =
    MOUSE_OPTION_TO_BUTTON[pan?.mouse as keyof typeof MOUSE_OPTION_TO_BUTTON] ??
    0;
  const zoomMouse =
    MOUSE_OPTION_TO_BUTTON[
      zoom?.mouse as keyof typeof MOUSE_OPTION_TO_BUTTON
    ] ?? 0;

  // 创建最终配置
  return {
    rotate: {
      ...(rotateMouse < 4 ? { button: rotateMouse } : { buttons: rotateMouse }),
      ctrlKey: rotate?.key === 'CTRL',
      shiftKey: rotate?.key === 'SHIFT',
      altKey: rotate?.key === 'ALT',
    },
    pan: {
      ...(panMouse < 4 ? { button: panMouse } : { buttons: panMouse }),
      ctrlKey: pan?.key === 'CTRL',
      shiftKey: pan?.key === 'SHIFT',
      altKey: pan?.key === 'ALT',
    },
    zoom: {
      ...((zoom?.mouse as keyof typeof MOUSE_OPTION_TO_BUTTON) !==
      'mouse-middle-move'
        ? zoomMouse < 4
          ? { button: zoomMouse }
          : { buttons: zoomMouse }
        : {}),
      ctrlKey: zoom?.key === 'CTRL',
      shiftKey: zoom?.key === 'SHIFT',
      altKey: zoom?.key === 'ALT',
      wheel:
        (zoom?.mouse as keyof typeof MOUSE_OPTION_TO_BUTTON) ===
        'mouse-middle-move',
    },
  };
}
